package com.ruoyi.whole.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.whole.domain.DmsSaleReport;
import com.ruoyi.whole.service.IDmsSaleReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 实销上报Controller
 * 
 * @author liuchuanfa
 * @date 2024-03-10
 */
@RestController
@RequestMapping("/whole/report")
public class DmsSaleReportController extends BaseController
{
    @Autowired
    private IDmsSaleReportService dmsSaleReportService;

    /**
     * 查询实销上报列表
     */
    @PreAuthorize("@ss.hasPermi('whole:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmsSaleReport dmsSaleReport)
    {
        startPage();
        List<DmsSaleReport> list = dmsSaleReportService.selectDmsSaleReportList(dmsSaleReport);
        return getDataTable(list);
    }

    /**
     * 导出实销上报列表
     */
    @PreAuthorize("@ss.hasPermi('whole:report:export')")
    @Log(title = "实销上报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsSaleReport dmsSaleReport)
    {
        List<DmsSaleReport> list = dmsSaleReportService.selectDmsSaleReportList(dmsSaleReport);
        ExcelUtil<DmsSaleReport> util = new ExcelUtil<DmsSaleReport>(DmsSaleReport.class);
        util.exportExcel(response, list, "实销上报数据");
    }

    /**
     * 获取实销上报详细信息
     */
    @PreAuthorize("@ss.hasPermi('whole:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dmsSaleReportService.selectDmsSaleReportById(id));
    }

    /**
     * 新增实销上报
     */
    @PreAuthorize("@ss.hasPermi('whole:report:add')")
    @Log(title = "实销上报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsSaleReport dmsSaleReport)
    {
        return toAjax(dmsSaleReportService.insertDmsSaleReport(dmsSaleReport));
    }

    /**
     * 修改实销上报
     */
    @PreAuthorize("@ss.hasPermi('whole:report:edit')")
    @Log(title = "实销上报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsSaleReport dmsSaleReport)
    {
        return toAjax(dmsSaleReportService.updateDmsSaleReport(dmsSaleReport));
    }

    /**
     * 删除实销上报
     */
    @PreAuthorize("@ss.hasPermi('whole:report:remove')")
    @Log(title = "实销上报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsSaleReportService.deleteDmsSaleReportByIds(ids));
    }
}
